package com.sample.jqgrid.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.sample.jqgrid.service.JqgridService;

@Service(value = "jqgridService") 
public class JqgridServiceImpl implements JqgridService {

	@Override
	public Map<String, Object> list() {
		Map<String, Object> map = new HashMap<String, Object>();
		
//		{ 
//			"total": "xxx", 
//			"page": "yyy", 
//			"records": "zzz",
//			"rows" : [
//				{"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
//				{"id" :"2", "cell":["cell21", "cell22", "cell23"]},
//				...
//			]
//		}
		
		map.put("page", 1);
		map.put("total", 10);
		map.put("records", 95);
		
		List<Map<String, Object>> rows = new ArrayList<Map<String, Object>>();
		
		Map<String, Object> row = null;
		row = new HashMap<String, Object>();
		row.put("id", 1);
		List<Object> cell = null;
		cell = new ArrayList<Object>();
		cell.add("column1-value");
		cell.add("<font color='red'>RED</font> content");
		cell.add("102");
		cell.add("2014-01-05");
		row.put("cell", cell);
		rows.add(row);
		
		row = new HashMap<String, Object>();
		row.put("id", 2);
		cell = new ArrayList<Object>();
		cell.add("column2-value");
		cell.add("<font color='blue'>BLUE</font> content");
		cell.add("103");
		cell.add("2014-02-05");
		row.put("cell", cell);
		rows.add(row);
		
		map.put("rows", rows);
		
		return map;
	}

}
